import BaseRApi from '@/framework/infra/base/BaseRApi'
import request from '@/utils/request'

export default class BaseCURDApi extends BaseRApi {
  // 更新接口方法
  update(updateParam) {
    const id = updateParam.id
    return request.put(this.absUrl(`/${id}`), updateParam)
  }

  beforeCreateOrUpdate(data) {

  }

  // 判断请求的是添加还是修改接口
  createOrUpdate(data) {
    if (data.id) {
      return this.update(data)
    }
    return this.create(data)
  }

  create(createParam) {
    return this.post('', createParam)
  }

  remove(id) {
    return request.delete(this.absUrl(`/${id}`))
  }

  removeMany(ids) {
    return request.delete(this.absUrl(), {
      data: {
        ids
      }
    })
  }

  online = (id) => this.request.post(this.absUrl('online'), {id})
  offline = (id) => this.request.post(this.absUrl('offline'), {id})
  batchOffline = (ids) => this.request.post(this.absUrl('batch-offline'), {ids})
  batchOnline = (ids) => this.request.post(this.absUrl('batch-online'), {ids})

  check({checkStatus, checkRemark, idList}) {
    return this.post('check', {
      status: checkStatus === 5 ? 1 : 0, remark: checkRemark, id: idList[0]
    })
  }

  setSortNum({id, sortNum}) {
    return this.post('set-sort-num', {id, sortNum})
  }

  setAsTop(id) {
    return this.post('set-as-top', {id})
  }
}
